<?php

declare (strict_types=1);

namespace App\Model;

use App\Service\FlyOrderService;
use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\Database\Model\Relations\HasOne;

/**
 * @property int $id
 * @property int $order_id
 * @property int $order_sku_id
 * @property int $moments_id
 * @property int $moments_product_id
 * @property string $single_price
 * @property int $quantity
 * @property string $commission_rate
 * @property string $subtotal
 * @property int $is_withdraw
 */
class FlyOrderCommission extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fly_order_commissions';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'order_id' => 'integer', 'order_sku_id' => 'integer', 'moments_id' => 'integer', 'moments_product_id' => 'integer', 'quantity' => 'integer', 'is_withdraw' => 'integer'];

    /**
     * 关联订单商品
     * @return HasMany
     */
    public function with_product()
    {
        return $this->hasMany(FlyOrderProduct::class, 'id', 'op_id');
    }

    /**
     * 关联订座订单
     * @return HasOne
     */
    public function with_order()
    {
        return $this->hasOne(FlyOrder::class, 'order_id', 'order_id')
            ->where('order_style', '=', FlyOrderService::STYLE_SEAT);
    }
}